package com.xiaoshuidi.cloud.module.iot.enums;

import org.springframework.util.StringUtils;

/**
 * 银通物联设备类型
 */
public enum YinTongDevTypeEnum {
    // 1冷水表，2电表，3门锁，4热水表
    COLD("1", "冷水表"),
    AMMETER("2", "电表"),
    LOCK("3", "门锁"),
    HOT("4", "热水表");
    private String code;
    private String desc;

    YinTongDevTypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public YinTongDevTypeEnum getInstanceByDevTypeCode(String yinTongDevTypeCode) {
        if (StringUtils.isEmpty(yinTongDevTypeCode)) {
            return null;
        }
        for (YinTongDevTypeEnum yinTongDevTypeEnum : values()) {
            if (yinTongDevTypeEnum.code.equals(yinTongDevTypeCode)) {
                return yinTongDevTypeEnum;
            }
        }
        return null;
    }

    public DeviceTypeEnum getDeviceTypeEnumByYinTongDevTypeCode(String yinTongDevTypeCode) {
        YinTongDevTypeEnum instanceByDevTypeCode = getInstanceByDevTypeCode(yinTongDevTypeCode);
        if (null == instanceByDevTypeCode) {
            return null;
        }
        if (instanceByDevTypeCode == COLD) {
            return DeviceTypeEnum.COLD_WATERMETE_TYPE_ENUM;
        }
        if (instanceByDevTypeCode == AMMETER) {
            return DeviceTypeEnum.AMMETER;
        }
        if (instanceByDevTypeCode == LOCK) {
            return DeviceTypeEnum.DOORLOCK;
        }
        if (instanceByDevTypeCode == HOT) {
            return DeviceTypeEnum.HOT_WATERMETE_TYPE_ENUM;
        }
        return null;
    }
}
